<?php
/**
 * 
require_once(dirname(__FILE__) . '/include/pagecode.php');
pagecode(__FILE__);
 */
function pagecode($file){
if($_SERVER['HTTP_HOST'] == 'a.com'){
?>

<div id="indexpagenav" style="">
    <style>
        #indexpagenav a{color:#fff;display:block;}
        #indexpagenav{position:fixed;left:-120px;top:0;width:200px;height:100vh;z-index:99999999999;background:#00000099;color:#fff;overflow-y: scroll;}
        #indexpagenav:hover{left:0;}
    </style>
    <script>
    $('#indexpagenav').on('click', 'a', function(){
        var _this = this;
        var cls = 'indexpagenav' + $(_this).data('cls');
        $('html,body').animate({
            scrollTop: $('.' + cls).offset().top - 120
        }, 1000)
    });
    </script>
</div>
<iframe id="indexpagepreifr" name="indexpagepreifr" class="c" style="display: none;"></iframe>
<?php $indexF = file_get_contents($file);$indexF = str_replace(array('<script','/script>'), array('<prejs','/prejs>'), substr($indexF, strpos($indexF, '<div class="indexbody">'))); ?>
<script>
    var a = <?php echo json_encode(array('a'=>$indexF))?>;
    $('#indexpagepreifr').contents().find('body').append(a.a);
</script>
<!--<script src="https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.5/clipboard.min.js"></script>-->
<script src="templates/default/js/clipboard.min.js"></script>
<script>
var _seleter = 'div,center,a';
$.each($('#indexpagepreifr').contents().find('.indexbody').eq(0).children(_seleter), function(i,v){
    var cd = $('.indexbody').eq(0).children(_seleter).eq(i);
    
    $(cd).addClass('indexpagenav' + i);
    var cls = $(v).attr('class');
    var dom = '<a class="indexpagenava" href="javascript:;" data-cls="' + i + '">' + cls + '</a>'
    $('#indexpagenav').append(dom)
    
    $(cd).after('<pre class="w1200 c indexpagepre" id="indexpagepre' + i + '"></pre>');
    $('#indexpagepre' + i).after('<button class="indexpageprebtncopy" data-clipboard-action="copy" data-clipboard-target="#indexpagepre' + i + '" style="display:none;position: absolute;">copy</button>');
    $('#indexpagepre' + i).text(
        $(v).prop("outerHTML")
        .replace(/&amp;/g, '&').replace(/&quot;/g, '\'')
        .replace(/&lt;/g, '<').replace(/&gt;/g, '>')
        .replace(/\<prejs/g, '<script').replace(/\/prejs\>/g, '/script>')
//        .replace(/="" /g, ' ')  //行内php被转义
        .replace(/\<\!--\?php/g, '\<\?php').replace(/\?--\>/g, '?>').replace(/---\>/g, '->')  //行内php被转义
    );
//    console.log(cd);
});
$('.indexpagepre').mouseover(function(){
    var t=$(this).offset().top;
    var l=$(this).offset().left;
    var w=$(this).width();
    $(this).next().css({'top':t,'left':l+w-60}).show();
}).mouseout(function(){
    $(this).next().hide();
});
$('.indexpageprebtncopy').mouseover(function(){
    $(this).show();
})

//复制文字,需要关闭页面所有禁止复制的代码
var indexpagepreaclipboard = new ClipboardJS('.indexpageprebtncopy');
indexpagepreaclipboard.on('success', function(e) {
    e.clearSelection();
//    alert('复制成功' + e.text, function(){});
    $('#btncopysucc').remove();
    $('body').prepend('<div id="btncopysucc" style="position:fixed;z-index:999;top:50%;left:50%;width:100px;height:60px;line-height:60px;text-align:center;margin-left:-30px;margin-top:-50px;background:#32593D;color:#fff;">复制成功</div>');
    setTimeout(function(){$('#btncopysucc').slideToggle(function(){$('#btncopysucc').remove()});}, 2000);
    return false;
});
</script>
<style>
.indexpagepre{font-size:10px;color:#6A8759;background:#2B2B2B;overflow:auto;min-height:35px;max-height:200px;margin:5px auto;}
</style>
<?php
}
}
?>